#include<bits/stdc++.h>
using namespace std;
#define int long long

int n;
int a[10][10];
bool vis[10][10];
int ans;

void dfs(int x1, int y1, int x2, int y2, int now) {
	if (x1 == n && y1 == n && x2 == n && y2 == n) {
		ans = max(ans, now);
		return ;
	}

	// 都向右
	if (y1 < n && y2 < n && !vis[x1][y1 + 1] && !vis[x2][y2 + 1]) {

		int t1 = a[x1][y1 + 1];
		a[x1][y1 + 1] = 0;
		int t2 = a[x2][y2 + 1];
		a[x2][y2 + 1] = 0;

		vis[x1][y1 + 1] = 1;
		vis[x2][y2 + 1] = 1;

		dfs(x1, y1 + 1, x2, y2 + 1, now + t1 + t2);

		a[x1][y1 + 2] = t1;
		a[x2][y2 + 1] = t2;

		vis[x1][y1 + 1] = 0;
		vis[x2][y2 + 1] = 0;
	}

	// 一个向右， 一个向下
	if (y1 < n && x2 < n && !vis[x1][y1 + 1] && !vis[x2 + 1][y2]) {

		int t1 = a[x1][y1 + 1];
		a[x1][y1 + 1] = 0;
		int t2 = a[x2 + 1][y2];
		a[x2 + 1][y2] = 0;

		vis[x1][y1 + 1] = 1;
		vis[x2 + 1][y2] = 1;

		dfs(x1, y1 + 1, x2 + 1, y2, now + t1 + t2);

		a[x1][y1 + 1] = t1;
		a[x2 + 1][y2] = t2;

		vis[x1][y1 + 1] = 0;
		vis[x2 + 1][y2] = 0;
	}

	// 一个向下， 一个向右
	if (x1 < n && y2 < n && !vis[x1 + 1][y1] && !vis[x2][y2 + 1]) {

		int t1 = a[x1 + 1][y1];
		a[x1 + 1][y1] = 0;
		int t2 = a[x2][y2 + 1];
		a[x2][y2 + 1] = 0;

		vis[x1 + 1][y1] = 1;
		vis[x2][y2 + 1] = 1;

		dfs(x1 + 1, y1, x2, y2 + 1, now + t1 + t2);

		a[x1 + 1][y1] = t1;
		a[x2][y2 + 1] = t2;

		vis[x1 + 1][y1] = 0;
		vis[x2][y2 + 1] = 0;
	}

	// 都向下
	if (x1 < n && x2 < n && !vis[x1 + 1][y1] && !vis[x2 + 1][y2]) {

		int t1 = a[x1 + 1][y1];
		a[x1 + 1][y1] = 0;
		int t2 = a[x2 + 1][y2];
		a[x2 + 1][y2] = 0;

		vis[x1 + 1][y1] = 1;
		vis[x2 + 1][y2] = 1;

		dfs(x1 + 1, y1, x2 + 1, y2, now + t1 + t2);

		a[x1 + 1][y1] = t1;
		a[x2 + 1][y2] = t2;

		vis[x1 + 1][y1] = 0;
		vis[x2 + 1][y2] = 0;
	}
}

signed main() {
	cin >> n;
	int x, y, z;
	while (cin >> x >> y >> z && (x || y || z))
		a[x][y] = z;
	dfs(1, 1, 1, 1, 0);
	cout << ans + a[1][1];
	return 0;
}
